#include <stdio.h>

int cmp_int(const void * p1, const void * p2)
{
	return *(int*)p1 - *(int*)p2;
}

void Swp(char* buf1, char* buf2)
{
	int temp = *buf1;
	*buf1 = *buf2;
	*buf2 = temp;
	buf1++;
	buf2++;
}
void Bubble_sort(void* base, size_t sz, size_t width, int(*cmp)(const void* p1, const void* p2))
{
	int i = 0;
	for (i = 0; i < sz - 1; i++)
	{
		int j = 0; 
		for (j = 0; j < sz - i - 1; j++)
		{
			if (cmp((char*)base + j * width, (char*)base + (j + 1) * width) > 0)
			{
				Swp((char*)base + j * width, (char*)base + (j + 1) * width);
			}
		}
	}
}

void Print_arr(int arr[], int sz)
{
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
}
void test()
{
	int arr[10] = { 9,8,5,3,2,6,4,3,2,1 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	Bubble_sort(arr, sz,sizeof(arr[0]),cmp_int);
	Print_arr(arr, sz);
}

int main()
{
	test();
	return 0;
}